<?php

namespace app\common\logic;

class Config extends LogicCore
{
	
    //重置/获取缓存
    public function _ResetCache($_Type = false){
		cache('sys.config', NULL);
        $_Data = $this->_Cache($_Type);
		if($_Type){
			return $_Data;
		}
	}
	
    //设置/获取缓存
    public function _Cache($_Type = false){
        //获取缓存中的配置信息
        $_Data = cache('sys.config');
        //判断缓存是否存在
        if(!$_Data){
            //从数据库中读取开启状态的模块
            $_Data = db('Config')->where(['status'=>1])->column('value','name');
			$_ModuleData = model('app\common\logic\Module')->_Cache(true);
			foreach($_ModuleData as $K => $V){
				if(!empty($V['setting'])){
					$_Data['Module_'.$K]=unserialize($V['setting']);
				}
			}
			$_PlugData = model('app\common\logic\Plug')->_Cache(true);
			foreach($_PlugData as $K => $V){
				if(!empty($V['setting'])){
					$_Data['Plug_'.$K]=unserialize($V['setting']);
				}
			}
            //将读取模块数据 进行缓存
            cache('sys.config',$_Data);
        }
		//读取公共函数扩展
		if($_Type){
			return $_Data;
		}
    }
}